package com.doit.day03

import org.apache.spark.Partitioner

/**
 * @Author: Hang.Nian.YY
 * @WX: 17710299606
 * @Tips: 学大数据 ,到多易教育
 * @DOC: https://blog.csdn.net/qq_37933018?spm=1000.2115.3001.5343
 * @Description:
 */
class MyPartitioner(num:Int) extends  Partitioner{

  override def numPartitions: Int = num

  override def getPartition(key: Any): Int = {
    val str = key.asInstanceOf[String]
    if (str.equals("a") || str.equals("b")){
      0
    }else if (str.equals("c") || str.equals("d")){
      1
    }else{
      2
    }

  }
}
